package com.burstly.lib.component.networkcomponent.burstly.html.mraid;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.component.networkcomponent.burstly.html.CloseableContainer;
import com.burstly.lib.util.Utils;

class MraidResizedView<T extends MraidView,  extends IActivityLifeCycleAware> extends MraidOverlay<T>
{
  private final int[] mLocationOnScreen;
  private ResizeProperties mResizeProperties;

  MraidResizedView(T paramT)
  {
    this(paramT, (ViewGroup)((Activity)paramT.getContext()).findViewById(16908290));
  }

  MraidResizedView(T paramT, ViewGroup paramViewGroup)
  {
    super(paramT, paramViewGroup);
    setApplyInOutAnimation(false);
    this.mLocationOnScreen = new int[2];
    paramT.getLocationInWindow(this.mLocationOnScreen);
    setRemoveOverlayedChildren(false);
  }

  private void configureContainer(CloseableContainer<?> paramCloseableContainer)
  {
    paramCloseableContainer.setCloseAreaGravity(this.mResizeProperties.getCustomClosePosition());
    paramCloseableContainer.setLayoutParams(createChildViewLayoutParams());
  }

  private FrameLayout.LayoutParams createChildViewLayoutParams()
  {
    int i = this.mResizeProperties.getWidth().intValue();
    int j = this.mResizeProperties.getHeight().intValue();
    FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams((int)Utils.scale(i), (int)Utils.scale(j), 51);
    Integer localInteger1 = this.mResizeProperties.getOffsetX();
    Integer localInteger2 = this.mResizeProperties.getOffsetY();
    int[] arrayOfInt = new int[2];
    ((MraidView)getChildView()).getContentParent().getLocationInWindow(arrayOfInt);
    if (localInteger1 != null)
      localLayoutParams.leftMargin = ((int)Utils.scale(localInteger1.intValue()) + (this.mLocationOnScreen[0] - arrayOfInt[0]));
    if (localInteger2 != null)
      localLayoutParams.topMargin = ((int)Utils.scale(localInteger2.intValue()) + (this.mLocationOnScreen[1] - arrayOfInt[1]));
    validateAllowOffscreen(localLayoutParams, ((MraidView)getChildView()).getContentParent());
    return localLayoutParams;
  }

  private void validateAllowOffscreen(FrameLayout.LayoutParams paramLayoutParams, ViewGroup paramViewGroup)
  {
    Integer localInteger1;
    Integer localInteger2;
    if ((!this.mResizeProperties.isAllowOffscreen()) && (paramViewGroup != null))
    {
      localInteger1 = Integer.valueOf(paramViewGroup.getWidth());
      localInteger2 = Integer.valueOf(paramViewGroup.getHeight());
      if (paramLayoutParams.leftMargin < 0)
        break label180;
      Integer localInteger4 = Integer.valueOf(localInteger1.intValue() - (paramLayoutParams.leftMargin + paramLayoutParams.width));
      if (localInteger4.intValue() < 0)
      {
        if (Math.abs(localInteger4.intValue()) > paramLayoutParams.leftMargin)
          break label165;
        paramLayoutParams.leftMargin -= Math.abs(localInteger4.intValue());
      }
      if (paramLayoutParams.topMargin < 0)
        break label226;
      Integer localInteger3 = Integer.valueOf(localInteger2.intValue() - (paramLayoutParams.topMargin + paramLayoutParams.height));
      if (localInteger3.intValue() < 0)
      {
        if (Math.abs(localInteger3.intValue()) > paramLayoutParams.topMargin)
          break label213;
        paramLayoutParams.topMargin -= Math.abs(localInteger3.intValue());
      }
    }
    label165: label180: label213: label226: 
    do
    {
      return;
      paramLayoutParams.leftMargin = 0;
      paramLayoutParams.width = Utils.getFillparentValue();
      break;
      paramLayoutParams.leftMargin = 0;
      if (Integer.valueOf(localInteger1.intValue() - paramLayoutParams.width).intValue() >= 0)
        break;
      paramLayoutParams.width = Utils.getFillparentValue();
      break;
      paramLayoutParams.topMargin = 0;
      paramLayoutParams.height = Utils.getFillparentValue();
      return;
      paramLayoutParams.topMargin = 0;
    }
    while (Integer.valueOf(localInteger2.intValue() - paramLayoutParams.height).intValue() >= 0);
    paramLayoutParams.height = Utils.getFillparentValue();
  }

  protected CloseableContainer<?> addChildToLayout(ViewGroup paramViewGroup, T paramT)
  {
    CloseableContainer localCloseableContainer = super.addChildToLayout(paramViewGroup, paramT);
    configureContainer(localCloseableContainer);
    paramT.requestFocus(130);
    return localCloseableContainer;
  }

  protected ViewGroup createContainerLayout()
  {
    return new FrameLayout(getContext());
  }

  CloseableContainer<?> getCloseableContainer()
  {
    return (CloseableContainer)this.mCloseableContainer;
  }

  void reConfigureCreatedContainer(ResizeProperties paramResizeProperties)
  {
    setResizeProperties(paramResizeProperties);
    ((MraidView)getChildView()).getLocationInWindow(this.mLocationOnScreen);
    configureContainer(getCloseableContainer());
  }

  void setResizeProperties(ResizeProperties paramResizeProperties)
  {
    this.mResizeProperties = paramResizeProperties;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.mraid.MraidResizedView
 * JD-Core Version:    0.6.2
 */